<template>
  <div>
    <el-cascader
      :options="treeData"
      size="mini"
      :props="{label:'name',value:'id'}"
      :value="value"
      style="width:300px"
      @change="change"
    />
  </div>
</template>

<script>
import { reqGetDepts } from '@/api/department'
import { translateToTreeData } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: []
    }
  },
  async created() {
    this.treeData = translateToTreeData((await reqGetDepts()).data, 0)
  },
  mounted() {

  },
  methods: {
    change(val) {
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style scoped>

</style>
